

import sys
import Image

from pylab import *
import reproj

from quaternion import *

imsrc = asarray(Image.open(sys.argv[1]))

imout = zeros((2000,2000,3), dtype=uint8)

psrc = array([0.0, 798, 489, 365])
#pout = array([0.0, 798, 489, 365])
pout = array([0.0, 1, 0, 0])


# R = identity(3)
R = Quat(-0.03250746,  0.33452959, -0.02493180).rot()
# R = (Quat(0,-sqrt(.5),0) * Quat(-0.03250746,  0.33452959, -0.02493180)).rot()
#R = Quat(0,0.3,0).rot()


lims=reproj.reprojection_limits(imout, imsrc, pout, psrc, R)

minx = lims[:,0].min()
maxx = lims[:,0].max()
miny = lims[:,1].min()
maxy = lims[:,1].max()

dimx = maxx-minx
dimy = maxy-miny
# dim = 300 * min(dimx,dimy)
dim = max(dimx,dimy)
f = 2000.0/dim

midx = (maxx+minx)/2
midy = (maxy+miny)/2

#pout = array([0.0, dim, -dim * minx, -dim*miny])
pout = array([0.0, f, 1000-midx*f,1000-midy*f])

reproj.reproject(imout, imsrc, pout, psrc, R)

ion()
imshow(imout)




